package com.zzrc.grape.service.impl;

import com.zzrc.grape.model.bank.ChangeBankStatusReq;
import com.zzrc.grape.service.BankService;
import com.zzrc.grape.util.BasePageData;
import com.zzrc.grape.util.WebResponseCode;
import com.zzrc.lotus.dao.mapper.BankAccountMapper;
import com.zzrc.lotus.dao.mapper.BankCardMapper;
import com.zzrc.lotus.dao.mapper.OperateBankCardMapper;
import com.zzrc.lotus.model.db.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BankServiceImpl implements BankService {
    @Resource
    BankCardMapper bankCardMapper;

    @Resource
    BankAccountMapper bankAccountMapper;

    @Resource
    OperateBankCardMapper operateBankCardMapper;

    @Override
    public int changeBankStatus(ChangeBankStatusReq changeBankStatusReq) {
        BankCardExample example = new BankCardExample();
        BankCardExample.Criteria criteria = example.createCriteria();
        criteria.andMobileEqualTo(changeBankStatusReq.getMobile());

        BankCard bankCard = new BankCard();
        bankCard.setPactPayStatus(changeBankStatusReq.getStatus());
        return bankCardMapper.updateByExampleSelective(bankCard, example);
    }

    @Override
    public BasePageData getBankCardList(String userGid) {
        BasePageData basePageData = new BasePageData();
        BankCardExample example = new BankCardExample();
        BankCardExample.Criteria criteria = example.createCriteria();
        criteria.andUserGidEqualTo(userGid);
        List<BankCard> bankCards = bankCardMapper.selectByExample(example);
        basePageData.setCode(WebResponseCode.SUCCESS);
        basePageData.setMsg(WebResponseCode.SUCCESSINFO);
        basePageData.setData(bankCards);
        return basePageData;
    }

    @Override
    public BasePageData getBankAccountList(String userGid) {
        BasePageData basePageData = new BasePageData();
        BankAccountExample example = new BankAccountExample();
        BankAccountExample.Criteria criteria = example.createCriteria();
        criteria.andUserGidEqualTo(userGid);
        List<BankAccount> bankCards = bankAccountMapper.selectByExample(example);
        basePageData.setCode(WebResponseCode.SUCCESS);
        basePageData.setMsg(WebResponseCode.SUCCESSINFO);
        basePageData.setData(bankCards);
        return basePageData;
    }

    @Override
    public BasePageData getOperateBankCardList(String userGid) {
        BasePageData basePageData = new BasePageData();
        OperateBankCardExample example = new OperateBankCardExample();
        OperateBankCardExample.Criteria criteria = example.createCriteria();
        criteria.andUserGidEqualTo(userGid);
        List<OperateBankCard> bankCards = operateBankCardMapper.selectByExample(example);
        basePageData.setCode(WebResponseCode.SUCCESS);
        basePageData.setMsg(WebResponseCode.SUCCESSINFO);
        basePageData.setData(bankCards);
        return basePageData;
    }
}
